package main

// 双向认证
import (
	"crypto/tls"
	"crypto/x509"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
)

type ServerHandler struct{}

func (s *ServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "测试")
}

func serverStart() {
	pool := x509.NewCertPool()
	caPath := "/Users/blue7/work/go-workplace/go-https/cert/rootCA.crt"
	crt, err := ioutil.ReadFile(caPath)
	if err != nil {
		log.Fatalln("读取证书错误", err)
	}
	pool.AppendCertsFromPEM(crt)

	s := &http.Server{
		Addr:    ":9898",
		Handler: &ServerHandler{},
		TLSConfig: &tls.Config{
			ClientCAs:  pool,
			ClientAuth: tls.RequireAndVerifyClientCert,
		},
	}
	s.ListenAndServeTLS("/Users/blue7/work/go-workplace/go-https/cert/server.crt", "/Users/blue7/work/go-workplace/go-https/cert/server.key")
}
